Lecture Notes

 

 

Course Outline

List the topics covered within each week.

 

Week

Topic(s)

  Homeworks assigned for the Lab of next week

1

Introduction to MATLAB Programming

 

LECTURE 1 :

Opening MATLAB and introducing the editor, command prompt, workspace, variables, arrays, operations on arrrays and plotting)

Lecture Notes

 

HOMEWORK for LAB 2 

a) Evaluate and store the sine and cosine values of the values from 5 to 360 15 by 15 and store them to the separated arrays called sines and cosines before plotting the sinusoidal graphs of these arrays, 

b) Evaluate the Tangent of these values by simply using these arrays

 

Solution

2

Variables and Control Structures (if, else-if, while, for…) with examples  Part 1

 

LECTURE 2 :

Defining Variables, storing values to the variables, operations on the variables,

a) Write a small program that simulates 1000000 throws of a dice and show that each face comes up at approximately same rate

b) Writing a function that swaps the indexes of two elements in an array and using this function to sort the elements in the array from the small to large

c) Generate N random numbers from 34 to 88 and store the odd numbers into array1, even numbers into array2

Solutions

HOMEWORK for LAB 3

Solution of Grade book example using if, else-if structures (retrieve a number from the user  while he doesn’t enter (-1) and display the corresponding letter grade on the screen

Solution

 

3

Variables and Control Structures (if, else-if, while, for…) with examples  Part 2

 

LECTURE 3 :

a) Writing a program that continuously takes 10 numbers from the user and displays whether the entered number is odd or even. Finally the program will also display whether the sum of all entered numbers are odd or even

b) Writing two functions that finds the minimum and maximum elements of an array and removes the from the array

Solutions

HOMEWORK for LAB 4 

Writing a MATLAB program that determines the solution of 5.th degree mathematical expression for any given a,b,c d,e,f of;

ax^5+bx^4+cx^3+dx^2+ex+f

Solution

4

Functions  and Arrays

 

LECTURE 4 :

a) Define 3 arrays called a,b and c, then write the functions topla, cikart carp, bol and us. Using these functions calculate [(a*b)^2-d]/c. Finally plot the results

b) Writing a program that generates 4 random even numbers from 38 to 83 different from each other 

Solutions

 

HOMEWORK for LAB 5 

a)Study recursive functions and write the function “faktoriyel” recursively without using the built in factorial function

b) write a program that calculates the transpose of an array

Solution

5

2 dimensional arrays in MATLAB

Usage of 2 dimensional arrays and ploting them in 3D in MATLAB

 

LECTURE 5 :

a) Again define 3 arrays called a,b and c (each 2D this time) , then write the functions topla, cikart carp, bol and us. Using these functions calculate [a+b^3]-c. Finally plot the 3D graph

 

b) Writing a function that checks whether the number is prime or not. Then using this function to write a program that finds 20 prime numbers greater than 100

c) Creating 10x10 array and converting the elements of the array to 0 if the number is even and 1 if the number is odd 

Solutions

 

HOMEWORK for LAB 6 

Create a an M x N array, fill it with random numbrs between a and b (taken from the user) Sort both rows and arrays

Solution

6

Accessing to array indexes, sorting and swapping

 

LECTURE 6

a) Assume you have a class of 40 students, assign them random grades between 0 and 100

Then plot the curve of the class

 

b) Writing the complete program of TOMBALA game. 

Solutions

HOMEWORK for LAB 7

a) An exponentially damped sinusoidal signal is defined by x(t) = 20sin(2π × 1000t − π/3)(e −at) where the exponential parameter a is variable, taking on the set of values a=250, 500, 750, 1000. For each a value draw x(t) signal for −2 ≤ t ≤ 2 miliseconds. Observe the effects of a on the signal. Using subplot command plot x(t) signals for all a values on the same graph.

b) Please wrie a MATLAB fprogram that assigns a set of numbers to an array then using a function "called rotate and written by you too" to rotate the array. The program will display evey step on the screen at each second as ;

123456 -> 612345 -> 561234 ->4561234->345612 -> 234561 -> 123456

Solutions

7

Usage of functions calling other functions and passing arrays between functions. Debugging and troubleshooting in Matlab Programs

 

LECTURE 7 :

 

a) Finding the perfect numbers up to the given numbers. (Perfect number is a positive integer that is equal to the sum of its propoer positive divisors, that is, the sum of its positive divisors excluding the number itself.)

b) Finding the subtraction of the sum of the odd numbers in an array from the numbers at the even indexes in the same array.

Solutions

 

HOMEWORK for LAB 8 

 Create a vector which is composed of 100 random integers from 1 to 99. By creating a matrix, place each element to different rows one by one according to the ranges. There will be 10 different ranges (1-9, 9-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70-79, 80-89, 90-99). Finally, count the number of values belonging to each range by using another vector that has all ones initially.

Solution

8

LECTURE 8 :

MIDTERM EXAM / RECITATION

 

HOMEWORK for LAB 9 

Take a value called "n" from the user, then Create two arrays with size floor(n/2) called arrayodd and arrayeven and fill them with random odd / even  numbers between 1-100. Then store them into another array called arrayone such that;

1.st element of arrayone  will be the first of arrayodd,

2.nd element of arrayone  will be the first of arrayeven + first of arrayone,

3.rd element will be the second of arrayodd + first 2 elemets of arrayone

and goes like this

 

Solution

9

Plotting, and some plotting properties of Matlab (Plot, subplot, stem, title, axis, legend, set, fill, grid, hold,…)

 

LECTURE 9 :

a) Write a MATLAB program that creates 2 arrays each of whih is filled by 5 random numbers. Then creates a 3rd array on which the array elements of other 2 arrays are taken 1 by 1 and added to previous item of 3rd array before appending it to the 3rd array & Midterm Solutions 

b) Write a MATLAB program that generates 100 random numbers between 1 and 100. THen stores them to an array for which the elemnts vith value in 0-10 range willbe stored n 1st row of the array, 10-20 range willbe stored n 2ndrow of the array etc. finaly displays the number elemets in each row seperately

c) do the samething by animating while loacting the values into the array and at the end the results will be platted.

 

Solutions

HOMEWORK for LAB 10

Write a program to find the number of days between 2 dates. User will enter 2 different dates where the first one should be older than the second one. This program should take into account the leap year (366 days in a year, occurs every 4 years period) as well as the number of days between months. There will be two different scenarios depending on whether or not the first month is smaller or larger than the second month.

Solution

10

Some built in functions, (int, trapz, diff, rand, mod, zeros, find, exp …),  their usage methods and examples

LECTURE 10 :

Write a program in which there will be n elements (the n value will be taken from the user) which will be shown by red diomonds and they will move in an area of 100x100 with random speeds and to random directions. they will also reflect when they hit to the borders or to eachother

Solution

HOMEWORK for LAB 11

Each new term in the Fibonacci sequence is the summation of the previous two terms. The first 10 Fibonacci sequence terms are as follows:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Write a Matlab code;

a) that finds the summation of both the even-valued terms and the odd-valued terms separately for the first 10 terms. This program should also count the total number of even-valued terms and the total number of odd-valued terms.

b) that finds the summation of both the even-valued terms and the odd-valued terms separately, where the term values do not exceed 2000. This program should also count the total number of even-valued terms and the total number of odd-valued terms.

Solutions

11

Developing Matlab programs including “Mobile objects” for simulation purpose

 

LECTURE 11 :

Write a program in which there will be n elements (the n value will be taken from the user) which will be shown by red diomonds and they will move in an area of 100x100 with random speeds and to random directions. they will also reflect when they hit to the borders or to eachother

Solution

HOMEWORK for LAB 12 

Write a Matlab program for the following dice game:

A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6. For each roll, the sum of the two upward faces is calculated.

Case1) If the sum is 7 or 11 on the first throw, the player wins.

Case2) If the sum is 2, 3 or 12 on the first throw, the player loses.

Case3) If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, the sum becomes the player's point. In order to win, player must continue rolling two dice until the new sum will equal to the player's point. In that case, you should count how many times the roll has thrown to reach the point.

Solution

12

Managing the distributed data by centralized way using multidimensional arrays in the simulations Part 1

 

LECTURE 12 :

a) Learning how to manage centralised data by differend nodes runing in the same area (a simulation perspective)

b) Writing tribonacci sequence. Tribonacci sequence terms are as follows: 1 1 2 4 8 15 29 56... and goes like this

Solutions

HOMEWORK for LAB 13 

a) Write a program to control if a given vector includes the Fibonacci sequence or not.

b) Take an input N value from the user. Create a N-valued vector which includes only even and non-recurring random numbers ranging in between 27 to 63. For each number in the array, calculate the absolute difference from the ones digit value and the tens digit value. If this difference is smaller than 5, then place this number into another array. Finally, display this final array on the screen.

c) Write a program to reverse the digits of the given number.

d) Store the numbers from 1 to 1000 to the following arrays

    -1st array includes non-prime and non-perfect numbers

   -2nd array includes non-prime and perfect numbers

   -3rd array includes prime and non-perfect numbers

   -4th array includes prime and perfect numbers

Solutions

13

Recitation

 

LECTURE 13 :

Recitation

 

 

 

     

 

     No Homework